package com.easyfun.healthmagicbox.alarmclock;

import com.easyfun.healthmagicbox.R;
import com.easyfun.healthmagicbox.pojo.ConstantData;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.PowerManager.WakeLock;
import android.os.Vibrator;
import android.view.Window;
import android.view.WindowManager;

public class AlarmActivity extends Activity {
	WakeLock mWakelock;
	Vibrator mVibrator;
	MediaPlayer alarmMusic;
	public static AlarmActivity instance = null;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		String personID = getIntent().getStringExtra(ConstantData.HMBPERSONID);
		String alarmDesc = getIntent().getStringExtra("alarmDesc");
		
		instance = this;
		final Window win = getWindow();
		win.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
				| WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
				| WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
				| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);

		// huoqu zhendong
		mVibrator = (Vibrator) this.getSystemService(Context.VIBRATOR_SERVICE);

		// mVibrator.vibrate( 10000);

		alarmMusic = MediaPlayerInstanse.getInstance(AlarmActivity.this).getMediaPlayer();
		mVibrator.vibrate(alarmMusic.getDuration());
		alarmMusic.start();

		// 创建一个对话框
		new AlertDialog.Builder(AlarmActivity.this).setTitle("闹钟")
				.setMessage("闹钟响了," + alarmDesc)
				.setPositiveButton("确定", new OnClickListener() {
					@Override
					public void onClick(DialogInterface dialog, int which) {
						// 停止音乐
						alarmMusic.stop();
						// tingzhizhendong
						mVibrator.cancel();
						// 结束该Activity
						AlarmActivity.this.finish();
					}
				}).show();
	}

	
}
